<template>
  <el-select
    v-model="selectedValue"
    clearable
    :multiple="multiple"
    :class="multiple ? 'yt-multiple' : ''"
    :placeholder="placeholder"
    @change="handleChange"
    :disabled="disabled"
  >
    <el-option
      v-for="(item, index) in items"
      :key="index"
      :label="item.name"
      :value="item.id"
    >
    </el-option>
  </el-select>
</template>

<script>
  import { getUserInfoByName } from '@/api/scheduleManager/worksDetails';
  export default {
    name: 'getTemplateSelectTwo',
    props: {
      selectType: {
        type: String,
        default: 'default'
      },
      placeholder: {
        type: String,
        default() {
          return this.$t('placeholder.choose')
        }
      },
      listData: {
        // 列表数据
        type: String,
        default: ''
      },
      multiple: {
        type: Boolean,
        default: false
      },
      codeDefault: '',
      allList: false,
      disabled: false,
      clearable: true,
      value: ''
    },
    data() {
      return {
        buList: [],
        bgList: [],
        selectedValue: null,
        items: [],
        map: new Map()
      };
    },
    methods: {
      getUserInfo() {
        getUserInfoByName().then(res => {
          console.log(res);
          this.items = Object.assign([], res.data.rows);
          // this.items = [];
          // this.items = Object.assign([], res.data);
        });
      },
      getBg() {
        selectBg().then(res => {
          this.items = [];
          this.items = Object.assign([], res.data);
        });
      },
      handleChange(val) {
        this.$emit('selectedChange', val, this.selectType);
      }
    },
    watch: {
      value(val) {
        console.log('12');
        if (this.multiple) {
          console.log(JSON.stringify(val));
          this.selectedValue = val;
        } else {
          this.selectedValue = val;
        }
      },
      listData() {
        console.log('22222222');
      },
      selectedValue(val) {
        this.$emit('input', val);
      }
    },
    mounted() {
      this.selectedValue = this.value;
      console.log(this.listData, 'projectNo');
      if (this.listData === 'projectEngineer') {
        this.getUserInfo();
      } else if (this.listData === 'signersignatory') {
        this.getUserInfo();
      }
    }
  };
</script>

<style scoped>
</style>
